package mpcs.utils
{
	import flash.events.MouseEvent;
	
	import flexlib.mdi.containers.MDIWindow;
	
	import mpcs.model.vo.GlobalVO;
	import mpcs.view.components.StartPanel;

	/**
	 * 管理一些显示面板
	 * @author zhangzuoqiang
	 */	
	public class ComponentManager {
		
		public function ComponentManager() {
		}
		
		/**实时位置窗口**/
		public static var locationMDIWindow:MDIWindow;
		
		/**个人信息窗口**/
		public static var userinfoMDIWindow:MDIWindow;
		
		/**历史数据窗口**/
		public static var historyMDIWindow:MDIWindow;
		
		/**更多服务窗口**/
		public static var moresMDIWindow:MDIWindow;
		
		/**Google搜索窗口**/
		public static var googleMDIWindow:MDIWindow;
		
		/**实时位置模块是否开启**/
		public static var isopen_location:Boolean = false;
		
		/**个人信息模块是否开启**/
		public static var isopen_userinfo:Boolean = false;
		
		/**历史数据模块是否开启**/
		public static var isopen_history:Boolean = false;
		
		/**更多服务模块是否开启**/
		public static var isopen_mores:Boolean = false;
		
		/**Google搜索模块是否开启**/
		public static var isopen_google:Boolean = false;
		
		/**开始面板**/
		private static var startPanel:StartPanel;
		
		/**获取设置好格式的开始面板，全局只有一个实例**/
		public static function getStartPanel():StartPanel {
			if(startPanel == null){
				trace("创建开始窗口成功 ... ");
				startPanel = new StartPanel();
				updateStartValues(startPanel);
				addStartPanelListener();
				return startPanel;
			}else{
				trace("开始窗口已经创建，返回 ... ");
				if(startPanel.visible == false)
					startPanel.visible = true;
//				addStartPanelListener();
				return startPanel;
			}
		}
		
		/**
		 *  为StartPanel添加鼠标事件监听
		 */		
		private static function addStartPanelListener():void {
			if(startPanel == null)
				return;
			startPanel.addEventListener(MouseEvent.MOUSE_OUT, outHandle);
			startPanel.addEventListener(MouseEvent.MOUSE_OVER, overHandle);
			startPanel.addEventListener(MouseEvent.MOUSE_UP, upHandle);
		}
		
		/**
		 *  移除StartPanel鼠标事件监听
		 */		
		private static function removeStartPanelListener():void {
			if(startPanel == null)
				return;
			startPanel.removeEventListener(MouseEvent.MOUSE_OUT, outHandle);
			startPanel.removeEventListener(MouseEvent.MOUSE_OVER, overHandle);
		}
		
		private static function outHandle(evt:MouseEvent):void {
			startPanel.visible = false;
//			removeStartPanelListener();
		}
		
		private static function overHandle(evt:MouseEvent):void {
			if(startPanel.visible == false)
				startPanel.visible = true;
//			removeStartPanelListener();
		}
		
		private static function upHandle(evt:MouseEvent):void {
			if(startPanel.visible == false)
				startPanel.visible = true;
		}
		
		/**初始化StartPanel的参数**/
		private static function updateStartValues(start:StartPanel):void {
			start.left = 0;
			start.bottom = 80;
			start.width = 120;
			start.height = 320;
		}
		
	}
}